<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>正在登录请稍等</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
		<meta http-equiv="Pragma" content="no-cache" />
		<meta http-equiv="Expires" content="0" />
		<link rel="stylesheet" type="text/css" href="css/common.css"/>
		<style type="text/css">
			body{
				position: absolute;
				width: 100%;
				height: 100%;
			}
			img{
				
				width: 100%;
				height: 100%;
			}
		</style>
	</head>
	<body>
		<img src="./img/loading.png"/>
	</body>
	<script src="js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript">
		function isNull(data){
		    return (data == "" || data == undefined || data == null || data == "null" || data == "undefined") ? true : false;
		}
		function getQueryString(name)
		{
		    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		    var r = window.location.search.substr(1).match(reg);
		    if(r!=null)return  unescape(r[2]); return null;
		}
		var base_url = 'http://www.yunnantese.com/';
		var nextType = getQueryString('nextType');//为了点击公众号中的消息能进行跳转，需要的参数
		var p_id = getQueryString("p_id");
		//alert(1111111+p_id);
		if(p_id){
			localStorage.p_id = p_id;//为了在微信中跳转到商品的详情页面。
		}
		//alert(22222222222+localStorage.p_id);
		var urls = encodeURI("http://www.yunnantese.com/loading.html?nextType="+nextType+"&p_id="+p_id);
		var weixin_code = getQueryString('code');
		sessionStorage.code = weixin_code;
		if(isNull(sessionStorage.getItem("u_id"))) {//以前判断是openid,现在判断用户是否创建了账号
			if(isNull(weixin_code)) {
				window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx338d962a035cfba2" + "&redirect_uri=" + urls + "&response_type=code&scope=snsapi_userinfo#wechat_redirect"
			} else {
				$.ajax({
					url: base_url + 'ZITAOHUI/callBack',
					data: {
						code: weixin_code
					},
					success: function(data) {
						console.log(data);
						u_id = data.extend.list.userMsg.user_Id;
						//alert("u_id:"+u_id);
						sessionStorage.userMsg = JSON.stringify(data.extend.list.userMsg);
						var status = data.extend.list.status;//是否绑定了手机号的状态  0已经绑定  除此之外都是没有绑定的
						sessionStorage.setItem("openid", data.extend.list.userMsg.openid);
						if(isNull(u_id)){}else{//如果uid存在的话，那么尝试获取店铺的id
							sessionStorage.u_id = u_id;
							sessionStorage.uid =u_id;
							
						}
						if(status==0||status=='0'){
							if(sessionStorage.getItem('urlPath')){
								window.location.replace(sessionStorage.getItem('urlPath'));//分享出去的链接跳到相应的页面
								sessionStorage.removeItem('urlPath')
							}else{
								window.location.replace('./index.html?nextType='+nextType+"&p_id="+p_id+"&time="+Math.random());//正常登陆的跳转页面
							} 
						}else{
							window.location.replace('./page/sign_in.html');//跳转到绑定手机号的页面
						}
					},
					error: function(data) {
						console.log(data)
						alert("登录信息过期,点击确认重新获取信息");
						window.location.href = "http://www.yunnantese.com/loading.html";
					}
				})
			}
		}else{
			
			setTimeout(function() {
				window.location.replace('./index.html?nextType='+nextType+"&p_id="+p_id) ;
			}, 1000)
		}
	</script>
</html>